<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;

$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return=array();
$uniacid=$_SESSION['uniacid'];
$mid=$_SESSION['uid'];
$return['setting']=$this->plugin_setting('basic');
if($_RQ['op']=='main'){
	$id=$_RQ['id'];
	$log=pdo_get('jy_sendgoods_ex_log',array('uniacid'=>$uniacid,'id'=>$_RQ['id']));
	$order=pdo_get('jy_sendgoods_order',array('uniacid'=>$uniacid,'id'=>$log['order_id']));
	$act=pdo_get('jy_sendgoods_act',array('uniacid'=>$uniacid,'id'=>$order['actid']));
	$goods=pdo_get('jy_weishop_goods',array('uniacid'=>$uniacid,'id'=>$act['goodsid']));
	$goods['option_title']=pdo_getcolumn('jy_weishop_goods_option',array('id'=>$order['optionid']),'title');
	//整理收货地址信息
	$member_address=pdo_getall('core_address',array('mid'=>$_SESSION['uid']));
	if($member_address){
		foreach($member_address as &$address){
			$address['pcd']=json_decode($address['pcd'],true);
			if($address['isdefault']){
				$item['addressid']=$address['id'];
				$item['address']=$address;
				break;
			}
		}
		if(!$item['addressid']){
			$item['addressid']=$member_address['0']['id'];
			$item['address']=$member_address['0'];
		}
	}
	$return['goods'] = $goods;
	$return['act']=$act;
	$return['log']=$log;
	$return['item']=$item;
	$return['member']=$member;
	$return['order']=$order;
	$return['params']=array();
	set_html('title','兑换商品');
	exi($return);

}
if($_RQ['op']=='exchange'){
	$post=get_postdata();
	
	$addressid=$post['addressid'];
	$order_id=$post['order_id'];
	$id=$post['id'];
	file_put_contents(ROOT_D.'/csssss.txt','addressid='.$addressid.';id='.$id);
	if(!$addressid){
		exi('请完善地址信息','error');
	}
	$data=array(
	'addressid'=>$addressid,
	'status'=>1,
	'isuse'=>1,
	'usetime'=>TIMESTAMP
	);
	pdo_update('jy_sendgoods_ex_log',$data,array('id'=>$id));
	$return['success']=1;
	exi($return);
	
}

